package dbu.dbase.version3;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.TreeSet;

import dbu.dbase.DBaseStructure;

public class MdxPage extends DBaseStructure {

	/** No of valid entries on current page */
	private int noOfEntries;
	private Collection<MdxEntry> entries;

	
	public MdxPage() {
		entries = new LinkedHashSet<MdxEntry>();
	}

	/**
	 * Read  
	 * @param stream
	 * @throws IOException
	 */
	@Override
	protected int read(InputStream stream) throws IOException {
		/** 4 byte */
		noOfEntries = readInt(stream);

		/**/System.out.println(this);

		int size = 4;
		
		/** Entries */
		for (int i = 0; i < noOfEntries; i++) {
			MdxEntry entry = new MdxEntry();
			size += entry.read(stream);
			/**/System.out.println(entry);
			entries.add(entry);
		}

		return size;
	}

	/**
	 * Write 
	 * @param stream
	 * @throws IOException
	 */
	protected void write(OutputStream stream) throws IOException {
		/** 4 byte */
		stream.write(noOfEntries);
	}

	@Override
	public String toString() {
		StringBuffer result = new StringBuffer();
		result.append("noOfEntries: "); result.append(noOfEntries); result.append("\n");
		return result.toString();
	}
}
